<?php

return [
    'module' => [
        'name' => 'coupon',
        'title' => '优惠券',
        'table' => 'coupons',
    ],
    
    'fields' => [
        'id' => [
            'type' => 'bigint',
            'length' => 20,
            'comment' => '优惠券ID',
            'unsigned' => true,
            'nullable' => false,
            'primary' => true,
            'auto_increment' => true,
            'required' => true,
        ],
        'name' => [
            'type' => 'varchar',
            'length' => 64,
            'comment' => '优惠券名称',
            'nullable' => false,
            'required' => true,
        ],
        'type' => [
            'type' => 'tinyint',
            'length' => 4,
            'comment' => '优惠券类型：1满减券，2折扣券',
            'nullable' => false,
            'required' => true,
            'default' => 1,
        ],
        'amount' => [
            'type' => 'decimal',
            'length' => '10,2',
            'comment' => '优惠金额/折扣率',
            'nullable' => false,
            'required' => true,
            'default' => 0.00,
        ],
        'min_amount' => [
            'type' => 'decimal',
            'length' => '10,2',
            'comment' => '最低使用金额',
            'nullable' => false,
            'required' => true,
            'default' => 0.00,
        ],
        'start_time' => [
            'type' => 'timestamp',
            'comment' => '开始时间',
            'nullable' => false,
            'required' => true,
        ],
        'end_time' => [
            'type' => 'timestamp',
            'comment' => '结束时间',
            'nullable' => false,
            'required' => true,
        ],
        'total' => [
            'type' => 'int',
            'length' => 11,
            'comment' => '发放总量',
            'nullable' => false,
            'required' => true,
            'default' => 0,
        ],
        'used' => [
            'type' => 'int',
            'length' => 11,
            'comment' => '已使用数量',
            'nullable' => false,
            'default' => 0,
        ],
        'per_limit' => [
            'type' => 'int',
            'length' => 11,
            'comment' => '每人限领数量',
            'nullable' => false,
            'required' => true,
            'default' => 1,
        ],
        'use_type' => [
            'type' => 'tinyint',
            'length' => 4,
            'comment' => '使用类型：0全场通用，1指定分类，2指定商品',
            'nullable' => false,
            'required' => true,
            'default' => 0,
        ],
        'product_ids' => [
            'type' => 'json',
            'comment' => '指定商品ID',
            'nullable' => false,
            'default' => '[]',
        ],
        'category_ids' => [
            'type' => 'json',
            'comment' => '指定分类ID',
            'nullable' => false,
            'default' => '[]',
        ],
        'code' => [
            'type' => 'varchar',
            'length' => 32,
            'comment' => '优惠码',
            'nullable' => false,
            'default' => '',
            'index' => true,
        ],
        'status' => [
            'type' => 'tinyint',
            'length' => 4,
            'comment' => '状态：0禁用，1启用',
            'nullable' => false,
            'required' => true,
            'default' => 1,
        ],
        'created_at' => [
            'type' => 'timestamp',
            'comment' => '创建时间',
            'nullable' => false,
            'default' => 'CURRENT_TIMESTAMP',
            'raw_default' => true,
        ],
        'updated_at' => [
            'type' => 'timestamp',
            'comment' => '更新时间',
            'nullable' => false,
            'default' => 'CURRENT_TIMESTAMP',
            'raw_default' => true,
            'extra' => 'ON UPDATE CURRENT_TIMESTAMP',
        ],
    ],
    
    'relations' => [
        'userCoupons' => [
            'type' => 'hasMany',
            'model' => 'UserCoupon',
            'foreign_key' => 'coupon_id',
        ],
    ],
    
    'queries' => [
        'name' => ['like', '%?%'],
        'type' => ['=', '?'],
        'code' => ['=', '?'],
        'status' => ['=', '?'],
        'start_time' => ['between', '?,?'],
        'end_time' => ['between', '?,?'],
        'created_at' => ['between', '?,?'],
    ],
]; 